package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.ModelMapper;
import com.bwie.pojo.Model;
import com.bwie.pojo.R;
import com.bwie.pojo.utile.Pageinfo;
import com.bwie.service.ModelService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author DarkClown
 * @date 2024-07-24 14:14
 * @project_name hight5
 * @parem
 **/
@Service
public class ModelServiceImpl extends ServiceImpl<ModelMapper, Model> implements ModelService {
    @Autowired
    ModelMapper modelMapper;

    @Override
    public R selectlist(Pageinfo pageinfo) {
        QueryWrapper<Model> queryWrapper = new QueryWrapper<>();

        if (!StringUtils.isEmpty(pageinfo.getKeyword())){
            queryWrapper.lambda().like(Model::getName,pageinfo.getKeyword());
        }

        List<Model> models = modelMapper.selectList(queryWrapper);

        return R.ok(models);
    }

    @Override
    public R insertlist(Model model) {
        int insert = modelMapper.insert(model);
        return R.ok();
    }


}
